package com.example.newhabitclock.HabitRoomPackage

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update

@Dao
interface HabitDao {
    @Insert //插入习惯
    suspend fun insert(habit: Habit)

    @Query("SELECT* FROM habits")
    fun getAllHabits(): LiveData<List<Habit>>

    @Update
    suspend fun updateHabit(habit:Habit)

    @Delete
    suspend fun delete(habit: Habit)

    @Query("SELECT *FROM habits WHERE id = :habitId")
    fun getHabitById(habitId:Int):LiveData<Habit>

    //每天凌晨重置所有习惯的打卡状态为false
    @Query("UPDATE habits SET isCheckIn = 0")
    suspend fun resetAllCheckIns()
}

















